//
//  CommunityPartyService.m
//  homeland
//
//  Created by caesar on 14-7-31.
//  Copyright (c) 2014年 xzysun. All rights reserved.
//

#import "CommunityPartyService.h"
#import "PartyEntity.h"

@implementation CommunityPartyService
//加载第一页数据
- (void)loadDataWithKey:(NSString *)keyOrNil{
    _currentPageNo = 1;
    if (self.dataList) {
        self.dataList = nil;
    }
    
    _dataItemName = @"PartyEntity";
    NSDictionary *_config = [super paramDic];
    PartyEntity *entity = [_config objectForKey:@"entity"];
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    // institutionId partyParentId partyName()
    [params setValue:[_config objectForKey:@"type"] forKey:@"partyCategory"];
    [params setValue:[[NSString alloc] initWithFormat:@"%d", entity.institutionId]   forKey:@"institutionId"];
    [params setValue:[[NSString alloc] initWithFormat:@"%@", entity.Id] forKey:@"partyParentId"];

    //查询参数
    if (keyOrNil) {
        [params setValue:keyOrNil forKey:@"partyName"];
    } else {
        [params setValue:@"" forKey:@"partyName"];
    }
    [self doHttpPost:SERVER_URL_PARTY_INFO headers:nil path:[NSString stringWithFormat:@"/%d",_currentPageNo] parameters:params];
}
//加载更多数据
- (void)loadMoreDataWithKey:(NSString *)keyOrNil{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    NSDictionary *_config = [super paramDic];
    PartyEntity *entity = [_config objectForKey:@"entity"];
    

    [params setValue:[_config objectForKey:@"type"] forKey:@"partyCategory"];
    [params setValue:[[NSString alloc] initWithFormat:@"%d", entity.institutionId]   forKey:@"institutionId"];
    [params setValue:[[NSString alloc] initWithFormat:@"%@", entity.Id] forKey:@"partyParentId"];
    if (keyOrNil) {
        [params setValue:keyOrNil forKey:@"partyName"];
    } else {
        [params setValue:@"" forKey:@"partyName"];
    }
    //民意征集/我要投票
    _dataItemName = @"PartyEntity";
    [self doHttpPost:SERVER_URL_PARTY_INFO headers:nil path:[NSString stringWithFormat:@"/%d",_currentPageNo + 1] parameters:params];
}

- (CGFloat)heightForCellAtRow:(NSIndexPath *)index{
    return 90.0f;//民意征集/我要投票每行105
}

/**展示数据*/
- (void)configCell:(UITableViewCell *)cell atIndex:(NSIndexPath *)index{
    if (self.dataList == nil || self.dataList.count == 0) {
        return;
    }
    //民意征集/我要投票
    PartyEntity *item = [self.dataList objectAtIndex:index.row];
    InfoWithPhoneAndMapCell *tempCell = (InfoWithPhoneAndMapCell *)cell;
    //标题
    tempCell.mainInfoLabel.text = item.partyName;
    //地址
    tempCell.additionalInfoLabel.text =item.partyAddress;
    //电话
   
    //电话按钮
    if (item.partyMobile&&item.partyMobile!=(id)[NSNull null]&&item.partyMobile.length>0) {
        [tempCell.phoneButton setEnabled:YES];
        [tempCell.phoneButton setBackgroundImage:[UIImage imageNamed:@"bt-电话.png"] forState:UIControlStateNormal];
        tempCell.phoneButton.tag = index.row;
        if (self.delegate && [self.delegate respondsToSelector:@selector(partyPhoneButtonAction:)]) {
            [tempCell.phoneButton addTarget:self.delegate action:@selector(partyPhoneButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        }
    } else {
        [tempCell.phoneButton setEnabled:NO];
        [tempCell.phoneButton setBackgroundImage:[UIImage imageNamed:@"bt-电话-灰.png"] forState:UIControlStateNormal];
    }
    //地图按钮
    if (item.point&&item.point!=(id)[NSNull null]&&item.point.length>0) {
        [tempCell.mapButton setEnabled:YES];
        [tempCell.mapButton setBackgroundImage:[UIImage imageNamed:@"bt-地图.png"] forState:UIControlStateNormal];
        tempCell.mapButton.tag = index;
        if (self.delegate && [self.delegate respondsToSelector:@selector(mapButtonAction:)]) {
            [tempCell.mapButton addTarget:self.delegate action:@selector(mapButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        }
    } else {
        [tempCell.mapButton setEnabled:NO];
        [tempCell.mapButton setBackgroundImage:[UIImage imageNamed:@"bt-地图-灰.png"] forState:UIControlStateNormal];
    }

    

}
@end
